package spring.velocity.mvc.lidian;

import java.util.List;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.springframework.web.servlet.ModelAndView;

public class TestListCourse extends AbstractDependencyInjectionSpringContextTests {
	@Override
	protected String[] getConfigLocations() {
		return new String[] { "file:D:/WORKSPACE/MyEclipse/springmock/WebRoot/WEB-INF/mvc-config.xml" };
	}

	@SuppressWarnings("static-access")
	public void testListCourse() throws Exception {
		ListCourse lc = (ListCourse) this.applicationContext.getBean("listCourse");

		MockHttpServletRequest request = new MockHttpServletRequest();
		MockHttpServletResponse response = new MockHttpServletResponse();

		request.setMethod("POST");

		request.addParameter("userid", "aa");
		request.addParameter("userpwd", "bb");

		ModelAndView mav = lc.handleRequest(request, response);

		assertEquals("courseList", mav.getViewName());
		assertNotNull(mav.getModelMap().get("courses"));
		List<Course> list = (List<Course>) mav.getModelMap().get("courses");
		for (Course c : list) {
			System.out.println(c.getId());
			System.out.println(c.getName());
		}

	}
}
